package com.drama.outtake.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.drama.outtake.common.Result;
import com.drama.outtake.dto.ShopDto;
import com.drama.outtake.service.ISearchService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author : 李先均
 * @Date 2023/3/25 23:50
 */
@RestController
@RequestMapping("/search")
@RequiredArgsConstructor
public class SearchController {

    private final ISearchService searchService;

    @GetMapping
    public Result<List<ShopDto>> search(@RequestParam("keyword") String keyword,
                                        @RequestParam("dineIn") boolean dineIn,
                                        @RequestParam("takeaway") boolean takeaway,
                                        @RequestParam("offlinePickUp") boolean offlinePickUp,
                                        @RequestParam("orderType") String orderType) {
        if (!StpUtil.isLogin()) {
            return Result.ok(searchService.search(null, keyword, dineIn, takeaway, offlinePickUp, orderType));
        }
/*        Long schoolId = Optional.ofNullable((User) StpUtil.getSession().get("userInfo", null))
                .map(User::getPhone)
                .orElse(null);*/
        Long schoolId = 1L;
        return Result.ok(searchService.search(schoolId, keyword, dineIn, takeaway, offlinePickUp, orderType));
    }
}
